﻿using ERPSystem.Common.Domains.supplier;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;

namespace BasicInformationCommon.API.BasicInformationCommons.Suppliers
{
    public class PurchaseGoodsFindHandler : IRequestHandler<PurchaseGoodsFindCommand, Result>
    {
        private readonly IBaseRepository<PurchasedGoods> purchasedGoodsbaseRepository;

        public PurchaseGoodsFindHandler(IBaseRepository<PurchasedGoods> purchasedGoodsbaseRepository)
        {
            this.purchasedGoodsbaseRepository = purchasedGoodsbaseRepository;
        }

        public async Task<Result> Handle(PurchaseGoodsFindCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var purchaseOrder = await (await purchasedGoodsbaseRepository.GetAll()).Where(x => x.PurchasedGoodsId == request.PurchasedGoodsId).FirstAsync();


                result.Data = purchaseOrder;

            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
